//
// Created by WQM on 2020/10/27.
//
#ifndef C_LEARN_ARRAY_TEST_H
#define C_LEARN_ARRAY_TEST_H

#endif //C_LEARN_ARRAY_TEST_H
#define count 6

/**
 * 数组练习
 * */
void array_test() {
    int age;
//    int count = 6;
    int n = 0, sum = 0;
    int students[count] = {0};
    while (1) {
        printf("您在录入学生年龄(-%d):", count - n);
        scanf("%d", &age);
        printf("你输入的是%d\n", age);
        if (age <= 0) break;
        if (n >= count) break;
        students[n] = age;
        sum += age;
        n++;
    }
    //统计学生年龄
    printf("录入统计\n");
    for (int i = 0; i < n; ++i) {
        if ((students[i]) > (sum / n)) printf("第%d个学生年龄 %d 大于 平均年龄 %d \n", i, students[i], sum / n);
        else if ((students[i]) < (sum / n)) printf("第%d个学生年龄 %d 小于 平均年龄 %d \n", i, students[i], sum / n);
        else printf("第%d个学生年龄 %d 等于 平均年龄 %d \n", i, students[i], sum / n);
    }
}

/**
 * 输入十个数 并 逆置
 * */
void reverse_array() {
    int c = 0, n;
    int max = 10, i = 0, j = max - 1 - i;
    int arr[11] = {0};//多留出一个（arr[10]）用于交换
    while (1) {
        if (c >= max)break;
        printf("请输入十个数字(-%d):", max - c);
        scanf("%d", &n);
        arr[c] = n;
        c++;
        printf(" \n");
    }
    for (int i = 0; i < max; i++) {
        printf("正常输出 ");
        printf("%d，", arr[i]);
    }
    printf(" \n");
    printf("交换\n");
    for (i = 0; i < 11; i++,j--) {
        if (i >= max / 2)break;
        printf("a[%d]=%d,a[%d]=%d \n", i, arr[i], j, arr[j]);
        arr[max] = arr[i];
        arr[i] = arr[j];
        arr[j] = arr[max];
        printf("a[%d]=%d,a[%d]=%d \n", i, arr[i], j, arr[j]);
        printf(" \n");
    }
    for (i=0; i < max; i++) {
        printf("逆序后：");
        printf("%d，", arr[i]);
    }
}